<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_attendances', function (Blueprint $table) {
            $table->id();
            // 关联项目 ID，表明该考勤记录所属的项目
            $table->unsignedBigInteger('project_id');
            // 关联员工 ID，标识考勤的员工
            $table->unsignedBigInteger('user_id');
            // 考勤日期
            $table->date('attendance_date');
            // 上班打卡时间
            $table->dateTime('in_time')->nullable();
            // 下班打卡时间
            $table->dateTime('out_time')->nullable();
            // 考勤状态，如正常、迟到、早退、旷工等
            $table->string('attendance_status')->default('present')->comment('present', 'late', 'early_leave', 'absent');
            // 工作时长，单位为小时
            $table->decimal('working_hours', 5, 2)->nullable();
            // 备注信息，可用于记录特殊情况
            $table->string('remarks')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_attendances');
    }
};
